#include<bits/stdc++.h>
using namespace std;

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    for(int k=1;k<=T;k++)
    {
        int n,m,l,V;
        int ans1=0,ans2=0;
        scanf("%d%d%d%d",&n,&m,&l,&V);
        int d[n+1],a[n+1],v[n+1],x[m+1],p[m+1];

        for(int i=1;i<=n;i++)
        {
            cin>>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++)
        {
            cin>>x[i];
        }
        for(int i=1;i<=n;i++)
        {
            if(a[i]==0&&v[i]<=V)
                break;
            if(a[i]==0&&v[i]>V)
            {
                for(int j=1;j<=m;j++)
                   {
                       int a1=0;
                      if(x[j]>d[i]){
                        p[j]++;a1++;}
                        if(a1>0){ans1++;}
                }
            }
            if(a[i]>0&&v[i]>=V)
            {
                for(int j=1;j<=m;j++)
                   {
                       int a2=0;
                      if(x[j]>d[i]){
                        p[j]++;a2++;}
                        if(a2>0){ans1++;}
            }}
            if(a[i]>0&&v[i]<V)
            {
                int a3=0;
                double b1=(V*V-v[i]*v[i])/(2*a[i]);
                for(int j=1;j<=m;j++)
                {
                    if(x[j]>d[i]+b1)
                    {
                        p[j]++;
                        a3++;
                    }
                    if(a3>0)
                        ans1++;
                }
            }
            if(a[i]<0&&v[i]<=V)
            {

                break;
            }
            if(a[i]<0&&v[i]>V)
            {
                int a4=0;
                double b2=(v[i]*v[i]-V*V)/(2*a[i]);
                for(int j=1;j<=m;j++)
                if(x[j]>d[i]&&x[j]<d[i]+b2)
                {
                    p[j]++;
                    a4++;
                }
                if(a4>0)
                    ans1++;
            }
        }
        for(int i=m;i>=1;i--)
        {
            if(p[i]==0)ans2++;
        }

        cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}
